home *** CD-ROM | disk | FTP | other *** search
/ PC Media 4 / PC MEDIA CD04.iso / share / prog / gcoope10 / shortint.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-22  |  3.0 KB  |  152 lines

  1.  
  2. /*
  3.  
  4.     ShortInt class definition   7/13/94 by Brian Lee Price
  5.  
  6.     This is a flag class.
  7.  
  8.     Compatible with experimental strong typing option
  9.  
  10.     Released as Public Domain    July, 1994.
  11.  
  12. */
  13.  
  14. #define CLASS ShortInt
  15.  
  16. #include "gcoope10.h"
  17.  
  18. #include <stdio.h>
  19.  
  20. object CLASS;
  21.  
  22. extern object String;
  23. extern object Char;
  24. extern object LongInt;
  25. extern object Unsigned;
  26.  
  27. USEGEN(changeVal);
  28. USEGEN(valueOf);
  29. USEGEN(asString);
  30. USEGEN(asHexStr);
  31. USEGEN(asChar);
  32. USEGEN(asLongInt);
  33. USEGEN(asUnsigned);
  34. USEGEN(asShortInt);
  35.  
  36. cmethod object m4New(object instance, short initVal)
  37. {
  38. if(((objHndl *) &instance)->fext)
  39.     {
  40.     short * ivptr;
  41.     if(NULL==(ivptr=getIVptr(instance))) return 0;
  42.     *ivptr=initVal;
  43.     }
  44. else
  45.     {
  46.     ((objHndl *) &instance)->fext=(tag)instance | ~SIGNMASK;
  47.     (tag) instance=0;
  48.     (short) instance=initVal;
  49.     }
  50. return instance;
  51. }
  52.  
  53.  
  54. imethod object m4changeVal(object instance, short newVal)
  55. {
  56. if(instance>=0)
  57.     {
  58.     short * ivptr;
  59.     if(NULL==(ivptr=getIVptr(instance))) return FUNCFAIL;
  60.     *ivptr=newVal;
  61.     }
  62. else (short) instance=newVal;
  63. return FUNCOKAY;
  64. }
  65.  
  66.  
  67. imethod short m4valueOf(object instance)
  68. {
  69. if(instance>=0)
  70.     {
  71.     short * ivptr;
  72.     ivptr=getIVptr(instance);
  73.     return *ivptr;
  74.     }
  75. else return (short) instance;
  76. }
  77.  
  78.  
  79. imethod object m4asString(object instance)
  80. {
  81. char strBuf[16];
  82. short a;
  83.  
  84. if(instance>=0) a=*((short *) getIVptr(instance));
  85. else a=(short) instance;
  86. sprintf(strBuf,"%d",(int) a);
  87. return g(New)(String,strBuf);
  88. }
  89.  
  90.  
  91. imethod object m4asHexStr(object instance)
  92. {
  93. char strBuf[16];
  94. short a;
  95.  
  96. if(instance>=0) a=*((short *) getIVptr(instance));
  97. else a=(short) instance;
  98. sprintf(strBuf, "%x", (unsigned) a);
  99. return g(New)(String,strBuf);
  100. }
  101.  
  102.  
  103. imethod object m4asChar(object instance)
  104. {
  105. short a;
  106.  
  107. if(instance>=0) a=*((short *) getIVptr(instance));
  108. else a=(short) instance;
  109. return g(New)(Char,(char) a);
  110. }
  111.  
  112.  
  113. imethod object m4asLongInt(object instance)
  114. {
  115. short a;
  116.  
  117. if(instance>=0) a=*((short *) getIVptr(instance));
  118. else a=(short) instance;
  119. return g(New)(LongInt,(long) a);
  120. }
  121.  
  122.  
  123. imethod object m4asUnsigned(object instance)
  124. {
  125. short a;
  126.  
  127. if(instance>=0) a=*((short *) getIVptr(instance));
  128. else a=(short) instance;
  129. return g(New)(Unsigned,(unsigned short) a);
  130. }
  131.  
  132.  
  133. CLASS_INSTALL
  134. {
  135. stat x=FUNCFAIL;
  136.  
  137. if(END==(CLASS=g(New)(Class, 0, sizeof(short), END))) goto end;
  138. if(addGMthd(CLASS, New, (method) m4New)) goto end;
  139. if(addGMthd(CLASS, GEN(changeVal), (method) m4changeVal)) goto end;
  140. if(addGMthd(CLASS, GEN(valueOf), (method) m4valueOf)) goto end;
  141. if(addGMthd(CLASS, GEN(asString), (method) m4asString)) goto end;
  142. if(addGMthd(CLASS, GEN(asHexStr), (method) m4asHexStr)) goto end;
  143. if(addGMthd(CLASS, GEN(asChar), (method) m4asChar)) goto end;
  144. if(addGMthd(CLASS, GEN(asLongInt), (method) m4asLongInt)) goto end;
  145. if(addGMthd(CLASS, GEN(asUnsigned), (method) m4asUnsigned)) goto end;
  146. if(addGMthd(CLASS, GEN(asShortInt), bounceBack)) goto end;
  147. x=FUNCOKAY;
  148.  
  149. end:
  150. return x;
  151. }
  152.